package cn.iocoder.yudao.module.infrastructure.dict.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
import cn.iocoder.yudao.module.infrastructure.dict.controller.admin.vo.data.DictDataSimpleRespVO;
import cn.iocoder.yudao.module.infrastructure.dict.dal.dataobject.DictDataDO;
import cn.iocoder.yudao.module.infrastructure.dict.service.DictDataService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 字典数据")
@RestController
@RequestMapping("/system/dict-data")
@Validated
public class DictDataControllerV2 {

    @Resource
    private DictDataService dictDataService;

    @GetMapping(value = {"simple-list-v2"})
    @Operation(summary = "获得全部字典数据列表", description = "一般用于管理后台缓存字典数据在本地")
    @PermitAll // 无需添加权限认证，因为前端全局都需要
    public CommonResult<List<DictDataSimpleRespVO>> getSimpleDictDataList() {
        List<DictDataDO> list = dictDataService.getEnabledAllDictDataList();
        return success(BeanUtils.toBean(list, DictDataSimpleRespVO.class));
    }

}
